package com.waleipt.api.es.tcptransport.status;

import org.junit.Test;

public class StatusTest {

	private static final byte STATUS_REQRES = 1 << 0;
    private static final byte STATUS_ERROR = 1 << 1;
    private static final byte STATUS_COMPRESS = 1 << 2;
    private static final byte STATUS_HANDSHAKE = 1 << 3;
    
    public static boolean isRequest(byte value) {
        return (value & STATUS_REQRES) == 0;
    }
    public static byte setRequest(byte value) {
        value &= ~STATUS_REQRES;
        return value;
    }
    
    
	@Test
	public void test()
	{
		System.err.println( "STATUS_REQRES    >(1 << 0)=0001="+STATUS_REQRES );
		System.err.println( "STATUS_ERROR     >(1 << 1)=0010="+STATUS_ERROR );
		System.err.println( "STATUS_COMPRESS  >(1 << 2)=0100="+STATUS_COMPRESS );
		System.err.println( "STATUS_HANDSHAKE >(1 << 3)=1000="+STATUS_HANDSHAKE );
		
		/**
		 * isRequest:
		 * 0000
		 * 0001
		 *=0000=true
		 *
		 * 1110
		 * 0001
		 *=0000=true
		 * 
		 */
		System.err.println( "isRequest ="+isRequest((byte)14) );
		
		/**
		 * setRequest
		 * 0001
		 *~0001=1110
		 * 1110
		 *&0001=0
		 * 
		 * 
		 */
		System.err.println( "isRequest ="+setRequest((byte)1) );
	}
}
